<!DOCTYPE HTML>

<html lang="en">
<head>

<title>WithMockUser (spring-security-docs 5.6.3 API)</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="../../../../../../stylesheet.css" title="Style">
<link rel="stylesheet" type="text/css" href="../../../../../../jquery/jquery-ui.css" title="Style">
<script type="text/javascript" src="../../../../../../script.js"></script>
<script type="text/javascript" src="../../../../../../jquery/jszip/dist/jszip.min.js"></script>
<script type="text/javascript" src="../../../../../../jquery/jszip-utils/dist/jszip-utils.min.js"></script>
<!--[if IE]>
<script type="text/javascript" src="../../../../../../jquery/jszip-utils/dist/jszip-utils-ie.min.js"></script>
<![endif]-->
<script type="text/javascript" src="../../../../../../jquery/jquery-3.5.1.js"></script>
<script type="text/javascript" src="../../../../../../jquery/jquery-ui.js"></script>
</head>
<body>
<script type="text/javascript"><!--
    try {
        if (location.href.indexOf('is-external=true') == -1) {
            parent.document.title="WithMockUser (spring-security-docs 5.6.3 API)";
        }
    }
    catch(err) {
    }
//-->
var pathtoroot = "../../../../../../";
var useModuleDirectories = true;
loadScripts(document, 'script');</script>
<noscript>
<div>JavaScript is disabled on your browser.</div>
</noscript>
<header role="banner">
<nav role="navigation">
<div class="fixedNav">

<div class="topNav"><a id="navbar.top">

</a>
<div class="skipNav"><a href="WithMockUser.html#skip.navbar.top" title="Skip navigation links">Skip navigation links</a></div>
<a id="navbar.top.firstrow">

</a>
<ul class="navList" title="Navigation">
<li><a href="../../../../../../index.html">Overview</a></li>
<li><a href="package-summary.html">Package</a></li>
<li class="navBarCell1Rev">Class</li>
<li><a href="package-tree.html">Tree</a></li>
<li><a href="../../../../../../deprecated-list.html">Deprecated</a></li>
<li><a href="../../../../../../index-all.html">Index</a></li>
<li><a href="../../../../../../help-doc.html">Help</a></li>
</ul>
</div>
<div class="subNav">
<ul class="navList" id="allclasses_navbar_top">
<li><a href="../../../../../../allclasses.html">All&nbsp;Classes</a></li>
</ul>
<ul class="navListSearch">
<li><label for="search">SEARCH:</label>
<input type="text" id="search" value="search" disabled="disabled">
<input type="reset" id="reset" value="reset" disabled="disabled">
</li>
</ul>
<div>
<script type="text/javascript"><!--
  allClassesLink = document.getElementById("allclasses_navbar_top");
  if(window==top) {
    allClassesLink.style.display = "block";
  }
  else {
    allClassesLink.style.display = "none";
  }
  //-->
</script>
<noscript>
<div>JavaScript is disabled on your browser.</div>
</noscript>
</div>
<div>
<ul class="subNavList">
<li>Summary:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li>Required&nbsp;|&nbsp;</li>
<li><a href="WithMockUser.html#annotation.type.optional.element.summary">Optional</a></li>
</ul>
<ul class="subNavList">
<li>Detail:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li><a href="WithMockUser.html#annotation.type.element.detail">Element</a></li>
</ul>
</div>
<a id="skip.navbar.top">

</a></div>

</div>
<div class="navPadding">&nbsp;</div>
<script type="text/javascript"><!--
$('.navPadding').css('padding-top', $('.fixedNav').css("height"));
//-->
</script>
</nav>
</header>

<main role="main">
<div class="header">
<div class="subTitle"><span class="packageLabelInType">Package</span>&nbsp;<a href="package-summary.html">org.springframework.security.test.context.support</a></div>
<h2 title="Annotation Type WithMockUser" class="title">Annotation Type WithMockUser</h2>
</div>
<div class="contentContainer">
<div class="description">
<ul class="blockList">
<li class="blockList">
<hr>
<pre>@Target({METHOD,TYPE})
@Retention(RUNTIME)
@Inherited
@Documented
<a href="WithSecurityContext.html" title="annotation in org.springframework.security.test.context.support">@WithSecurityContext</a>(<a href="WithSecurityContext.html#factory()">factory</a>=org.springframework.security.test.context.support.WithMockUserSecurityContextFactory.class)
public @interface <span class="memberNameLabel">WithMockUser</span></pre>
<div class="block">When used with <a href="WithSecurityContextTestExecutionListener.html" title="class in org.springframework.security.test.context.support"><code>WithSecurityContextTestExecutionListener</code></a> this annotation can be
added to a test method to emulate running with a mocked user. In order to work with
<code>MockMvc</code> The <a href="../../../core/context/SecurityContext.html" title="interface in org.springframework.security.core.context"><code>SecurityContext</code></a> that is used will have the following
properties:
<ul>
<li>The <a href="../../../core/context/SecurityContext.html" title="interface in org.springframework.security.core.context"><code>SecurityContext</code></a> created with be that of
<a href="../../../core/context/SecurityContextHolder.html#createEmptyContext()"><code>SecurityContextHolder.createEmptyContext()</code></a></li>
<li>It will be populated with an <a href="../../../authentication/UsernamePasswordAuthenticationToken.html" title="class in org.springframework.security.authentication"><code>UsernamePasswordAuthenticationToken</code></a> that uses
the username of either <a href="WithMockUser.html#value()"><code>value()</code></a> or <a href="WithMockUser.html#username()"><code>username()</code></a>,
<a href="../../../core/GrantedAuthority.html" title="interface in org.springframework.security.core"><code>GrantedAuthority</code></a> that are specified by <a href="WithMockUser.html#roles()"><code>roles()</code></a>, and a password
specified by <a href="WithMockUser.html#password()"><code>password()</code></a>.
</ul></div>
<dl>
<dt><span class="simpleTagLabel">Since:</span></dt>
<dd>4.0</dd>
<dt><span class="seeLabel">See Also:</span></dt>
<dd><a href="WithUserDetails.html" title="annotation in org.springframework.security.test.context.support"><code>WithUserDetails</code></a></dd>
</dl>
</li>
</ul>
</div>
<div class="summary">
<ul class="blockList">
<li class="blockList">

<section role="region">
<ul class="blockList">
<li class="blockList"><a id="annotation.type.optional.element.summary">

</a>
<h3>Optional Element Summary</h3>
<table class="memberSummary">
<caption><span>Optional Elements</span><span class="tabEnd">&nbsp;</span></caption>
<tr>
<th class="colFirst" scope="col">Modifier and Type</th>
<th class="colSecond" scope="col">Optional Element</th>
<th class="colLast" scope="col">Description</th>
</tr>
<tr class="altColor">
<td class="colFirst"><code>java.lang.String[]</code></td>
<th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="WithMockUser.html#authorities()">authorities</a></span></code></th>
<td class="colLast">
<div class="block">
The authorities to use.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><code>java.lang.String</code></td>
<th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="WithMockUser.html#password()">password</a></span></code></th>
<td class="colLast">
<div class="block">The password to be used.</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><code>java.lang.String[]</code></td>
<th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="WithMockUser.html#roles()">roles</a></span></code></th>
<td class="colLast">
<div class="block">
The roles to use.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><code><a href="TestExecutionEvent.html" title="enum in org.springframework.security.test.context.support">TestExecutionEvent</a></code></td>
<th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="WithMockUser.html#setupBefore()">setupBefore</a></span></code></th>
<td class="colLast">
<div class="block">Determines when the <a href="../../../core/context/SecurityContext.html" title="interface in org.springframework.security.core.context"><code>SecurityContext</code></a> is setup.</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><code>java.lang.String</code></td>
<th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="WithMockUser.html#username()">username</a></span></code></th>
<td class="colLast">
<div class="block">The username to be used.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><code>java.lang.String</code></td>
<th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="WithMockUser.html#value()">value</a></span></code></th>
<td class="colLast">
<div class="block">Convenience mechanism for specifying the username.</div>
</td>
</tr>
</table>
</li>
</ul>
</section>
</li>
</ul>
</div>
<div class="details">
<ul class="blockList">
<li class="blockList">

<section role="region">
<ul class="blockList">
<li class="blockList"><a id="annotation.type.element.detail">

</a>
<h3>Element Detail</h3>
<a id="value()">

</a>
<ul class="blockList">
<li class="blockList">
<h4>value</h4>
<pre>java.lang.String&nbsp;value</pre>
<div class="block">Convenience mechanism for specifying the username. The default is "user". If
<a href="WithMockUser.html#username()"><code>username()</code></a> is specified it will be used instead of <a href="WithMockUser.html#value()"><code>value()</code></a></div>
<dl>
<dt><span class="returnLabel">Returns:</span></dt>
</dl>
<dl>
<dt>Default:</dt>
<dd>"user"</dd>
</dl>
</li>
</ul>
</li>
</ul>
</section>
<section role="region">
<ul class="blockList">
<li class="blockList"><a id="username()">

</a>
<ul class="blockList">
<li class="blockList">
<h4>username</h4>
<pre>java.lang.String&nbsp;username</pre>
<div class="block">The username to be used. Note that <a href="WithMockUser.html#value()"><code>value()</code></a> is a synonym for
<a href="WithMockUser.html#username()"><code>username()</code></a>, but if <a href="WithMockUser.html#username()"><code>username()</code></a> is specified it will take
precedence.</div>
<dl>
<dt><span class="returnLabel">Returns:</span></dt>
</dl>
<dl>
<dt>Default:</dt>
<dd>""</dd>
</dl>
</li>
</ul>
</li>
</ul>
</section>
<section role="region">
<ul class="blockList">
<li class="blockList"><a id="roles()">

</a>
<ul class="blockList">
<li class="blockList">
<h4>roles</h4>
<pre>java.lang.String[]&nbsp;roles</pre>
<div class="block"><p>
The roles to use. The default is "USER". A <a href="../../../core/GrantedAuthority.html" title="interface in org.springframework.security.core"><code>GrantedAuthority</code></a> will be created
for each value within roles. Each value in roles will automatically be prefixed
with "ROLE_". For example, the default will result in "ROLE_USER" being used.
</p>
<p>
If <a href="WithMockUser.html#authorities()"><code>authorities()</code></a> is specified this property cannot be changed from the
default.
</p></div>
<dl>
<dt><span class="returnLabel">Returns:</span></dt>
</dl>
<dl>
<dt>Default:</dt>
<dd>{"USER"}</dd>
</dl>
</li>
</ul>
</li>
</ul>
</section>
<section role="region">
<ul class="blockList">
<li class="blockList"><a id="authorities()">

</a>
<ul class="blockList">
<li class="blockList">
<h4>authorities</h4>
<pre>java.lang.String[]&nbsp;authorities</pre>
<div class="block"><p>
The authorities to use. A <a href="../../../core/GrantedAuthority.html" title="interface in org.springframework.security.core"><code>GrantedAuthority</code></a> will be created for each value.
</p>
<p>
If this property is specified then <a href="WithMockUser.html#roles()"><code>roles()</code></a> is not used. This differs from
<a href="WithMockUser.html#roles()"><code>roles()</code></a> in that it does not prefix the values passed in automatically.
</p></div>
<dl>
<dt><span class="returnLabel">Returns:</span></dt>
</dl>
<dl>
<dt>Default:</dt>
<dd>{}</dd>
</dl>
</li>
</ul>
</li>
</ul>
</section>
<section role="region">
<ul class="blockList">
<li class="blockList"><a id="password()">

</a>
<ul class="blockList">
<li class="blockList">
<h4>password</h4>
<pre>java.lang.String&nbsp;password</pre>
<div class="block">The password to be used. The default is "password".</div>
<dl>
<dt><span class="returnLabel">Returns:</span></dt>
</dl>
<dl>
<dt>Default:</dt>
<dd>"password"</dd>
</dl>
</li>
</ul>
</li>
</ul>
</section>
<section role="region">
<ul class="blockList">
<li class="blockList"><a id="setupBefore()">

</a>
<ul class="blockListLast">
<li class="blockList">
<h4>setupBefore</h4>
<pre>@AliasFor(annotation=<a href="WithSecurityContext.html" title="annotation in org.springframework.security.test.context.support">WithSecurityContext.class</a>)
<a href="TestExecutionEvent.html" title="enum in org.springframework.security.test.context.support">TestExecutionEvent</a>&nbsp;setupBefore</pre>
<div class="block">Determines when the <a href="../../../core/context/SecurityContext.html" title="interface in org.springframework.security.core.context"><code>SecurityContext</code></a> is setup. The default is before
<a href="TestExecutionEvent.html#TEST_METHOD"><code>TestExecutionEvent.TEST_METHOD</code></a> which occurs during
<code>TestExecutionListener.beforeTestMethod(TestContext)</code></div>
<dl>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>the <a href="TestExecutionEvent.html" title="enum in org.springframework.security.test.context.support"><code>TestExecutionEvent</code></a> to initialize before</dd>
<dt><span class="simpleTagLabel">Since:</span></dt>
<dd>5.1</dd>
</dl>
<dl>
<dt>Default:</dt>
<dd>org.springframework.security.test.context.support.TestExecutionEvent.TEST_METHOD</dd>
</dl>
</li>
</ul>
</li>
</ul>
</section>
</li>
</ul>
</div>
</div>
</main>

<footer role="contentinfo">
<nav role="navigation">

<div class="bottomNav"><a id="navbar.bottom">

</a>
<div class="skipNav"><a href="WithMockUser.html#skip.navbar.bottom" title="Skip navigation links">Skip navigation links</a></div>
<a id="navbar.bottom.firstrow">

</a>
<ul class="navList" title="Navigation">
<li><a href="../../../../../../index.html">Overview</a></li>
<li><a href="package-summary.html">Package</a></li>
<li class="navBarCell1Rev">Class</li>
<li><a href="package-tree.html">Tree</a></li>
<li><a href="../../../../../../deprecated-list.html">Deprecated</a></li>
<li><a href="../../../../../../index-all.html">Index</a></li>
<li><a href="../../../../../../help-doc.html">Help</a></li>
</ul>
</div>
<div class="subNav">
<ul class="navList" id="allclasses_navbar_bottom">
<li><a href="../../../../../../allclasses.html">All&nbsp;Classes</a></li>
</ul>
<div>
<script type="text/javascript"><!--
  allClassesLink = document.getElementById("allclasses_navbar_bottom");
  if(window==top) {
    allClassesLink.style.display = "block";
  }
  else {
    allClassesLink.style.display = "none";
  }
  //-->
</script>
<noscript>
<div>JavaScript is disabled on your browser.</div>
</noscript>
</div>
<div>
<ul class="subNavList">
<li>Summary:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li>Required&nbsp;|&nbsp;</li>
<li><a href="WithMockUser.html#annotation.type.optional.element.summary">Optional</a></li>
</ul>
<ul class="subNavList">
<li>Detail:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li><a href="WithMockUser.html#annotation.type.element.detail">Element</a></li>
</ul>
</div>
<a id="skip.navbar.bottom">

</a></div>

</nav>
</footer>
<script>if (window.parent == window) {(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','//www.google-analytics.com/analytics.js','ga');ga('create', 'UA-2728886-23', 'auto', {'siteSpeedSampleRate': 100});ga('send', 'pageview');}</script><script defer src="https://static.cloudflareinsights.com/beacon.min.js/v652eace1692a40cfa3763df669d7439c1639079717194" integrity="sha512-Gi7xpJR8tSkrpF7aordPZQlW2DLtzUlZcumS8dMQjwDHEnw9I7ZLyiOj/6tZStRBGtGgN6ceN6cMH8z7etPGlw==" data-cf-beacon='{"rayId":"7040f6bcba7897cf","token":"bffcb8a918ae4755926f76178bfbd26b","version":"2021.12.0","si":100}' crossorigin="anonymous"></script>
</body>
</html>
